﻿using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;

namespace Game.FlowField.Burst
{
    [BurstCompile]
    public partial struct CopyGridIndexToJob : IJobParallelForBatch
    {
        [WriteOnly]
        public NativeArray<int> GridIndexToArray;

        [ReadOnly]
        public NativeArray<Unit> UnitArray;

        public void Execute(int startIndex, int count)
        {
            for (int i = 0; i < count; i++)
            {
                var realIndex = startIndex + i;
                var unit = this.UnitArray[realIndex];
                this.GridIndexToArray[realIndex] = unit.IsAlive ? this.UnitArray[realIndex].GridIndexTo : -1;
            }
        }
    }
}
